<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>微博字数统计</title>
    <style type="text/css">
        .textColor {
            color: #C00;
        }
        
        .input {
            height: 60px;
            width: 400px
        }
    </style>
    <script>
        window.addEventListener('load', function() {
            var p0 = document.querySelector('#div1 p');
            // 获取字数显示元素
            var textColor = document.querySelector('.textColor');
            // 获取文本框元素
            var textBox = document.querySelector('.input');
            // 要求在文本框输入字符，上方textColor显示10减文本框字符串长度数量
            textBox.addEventListener('keyup', function() {
                var length = this.value.length;
                var textNum = 10 - length;
                textColor.innerHTML = textNum;
                if (length >= 10) {
                    textBox.disabled = "true";
                };
            })
        })
    </script>
</head>

<body>
    <div id="div1">
        <form action="" method="post">
            <p>你还可以输入<var class="textColor">10</var>个字符。</p>
            <p class="textinput">
                <textarea maxlength="110" class="input"></textarea>
            </p>
        </form>
    </div>
</body>

</html>